/**
 * Created by admin on 2017/5/3.
 */
(function ($, document) {
    /*------------------初始化字段-------------------------------*/
    var lou_workcity1 = "";//公司地址
    var entryTime1 = "";//入职时间
    /*-----------------初始化PopPicker对象-----------------------*/
    var cityPicker = new $.PopPicker({layer: 3});
    var myDate = new Date();
    var nowYear = myDate.getFullYear();
    /*------------------给初始化PopPicker对象赋值----------------*/
    var options = JSON.parse('{"type":"date","beginYear":"1949","endYear":' + nowYear + '}');
    var entryTime = new $.DtPicker(options);
    cityPicker.setData(cityData3);
    /*-------------------------定义公共方法(绑定数据)----------------------------*/

    function pickevent(mm, nn, cc, dd) {
        document.getElementById(mm).addEventListener('tap', function () {
                if (mm.indexOf("Time") > 0) {
                    nn.show(function (e) {
                        document.getElementById(dd).innerText = e.text;
                    });
                }
                else {
                    nn.show(function (e) {
                        document.getElementById(dd).innerText = e[0].text;
                        cc = e[0].value;
                        console.log(cc);
                        document.getElementById(mm).style.color = 'black';
                        sessionStorage.setItem(dd, cc);
                    });
                }
            }
        , false);
    }

    function pickeventcity(mm, nn, cc, dd) {
        document.getElementById(mm).addEventListener('tap', function () {
            nn.show(function (items) {
                document.getElementById(dd).innerText = items[0].text + items[1].text+items[2].text;
                cc = items[0].text +items[1].text+items[2].text;
                var aaa = items[2].value;
                console.log(cc);
                sessionStorage.setItem(dd, cc);
                sessionStorage.setItem(dd + "_code", aaa);
                document.getElementById(mm).style.color = 'black';
                //返回 false 可以阻止选择框的关闭
                //return false;
            });
        }, false);
    }

    /*------------------------绑定pickevent----------------------------*/
    pickeventcity('conpanycity', cityPicker, lou_workcity1, "lou_workcity1"); //公司位置
    pickevent('entryTime', entryTime, entryTime1, 'entryTime1');//入职时间

})(mui, document);
$(function(){










/*---------------------------------*/


    var consume_time = Date.parse(new Date());
    var header = tool.header;
    header.public_key =localStorage.getItem("public_key");//获取公钥
    header.app_key =localStorage.getItem("app_key");//获取app标识
    header.source = localStorage.getItem("source");//用户来源
    header.client_id = localStorage.getItem("client_id");//用户手机唯一标识
    header.channel =localStorage.getItem("channel");//打包渠道
    header.app_version =localStorage.getItem("app_version");//APP版本号
    header.timestamp = new Date().getTime();



    function OnLoadInfo() {
        var flag = localStorage.getItem("flag");
        if (flag == 2) {
            var data = {
                user_id: localStorage.getItem("user_id")
            };
            var paramsStr = tool.getparamsStr(data);
            var signaturesign = header.public_key + header.app_key + header.source + header.channel + header.client_id + header.app_version + paramsStr + header.timestamp;
            //签名信息MD5加密
            var signaturesignature = hex_md5(signaturesign);
            header.signature = signaturesignature;
            var urls = tool.httpsUrl + "";
            tool.ajax(urls, header, data, function (data) {

                console.log(data);
            });
        }
    }
    OnLoadInfo();



    /*-----------------------------------公司信息提交按钮------------------------------------------------*/
    $('#workBtn').click(function () {
        var data = {
            ad_code: '',
            ad_path: '',
            company_name: '',
            consume_time: '',
            detail_address: '',
            hire_date: '',
            job_title: '',
            telephone: '',
            user_id: ''
        };

        data.ad_path = sessionStorage.getItem("lou_workcity1");
        data.ad_code = parseInt(sessionStorage.getItem("lou_workcity1_code"));
        data.hire_date = $('#entryTime').html();
        data.company_name = $("#companyNmae").val();
        data.telephone = $('#companyPhone').val();
        data.job_title = $('#companyPosition').val();
        data.detail_address = $('#detaiAddress').val();
        data.user_id = parseInt(localStorage.getItem("user_id"));
        data.consume_time = new Date().getTime() - consume_time;


        //填写联系人信息签名信息
        for(var i in data){
            if(data[i]==" "){
                mui.alert("完整信息", '提示', function () {
                    console.log(3);
                    $('#companyPhone').focus();
                });
                throw "1";
            }
        }
        header.timestamp = new Date().getTime();
        var paramsStr= tool.getparamsStr(data);
        signaturesign = header.public_key + header.app_key + header.source + header.channel + header.client_id + header.app_version + paramsStr + header.timestamp;
        //签名信息MD5加密
        signaturesignature = hex_md5(signaturesign);
        header.signature = signaturesignature;
        var url = tool.httpsUrl + "/archives/postUserJobInfo";
        tool.ajax(url, header, data, function (data) {
            if(data.success){
               localStorage.setItem("workInfo","1");
               window.location.href="payroll_in_information.html";
            }
        });
    })
});